#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int h, d;
bool check(int x) {
  int y = d / (x + 1);
  int z = d % (x + 1);
  ll tot = h + x;
  __int128_t sum = __int128_t(x + 1 - z) * (1ll * y * (y + 1) / 2);
  __int128_t sum2 = __int128_t(z) * (1ll * (y + 1) * (y + 2) / 2);
  return sum + sum2 < tot;
}
void solve() {
  cin >> h >> d;
  int l = 0, r = d;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l + d << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}